<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <script>
      class A extends Object {
        constructor(name) {
          super();
          this.name = name;
          this.hobbies = ["hiking", "walking"];
          this.shout = function () {
            console.log(this.name + " shouting");
          };
        }
        static xxx(){

        }

        width = 100;
        height = 200;
        cry() {
          console.log("cry : ", this);
          console.log("cry : ", this.name);
        }
        cry2 = function () {
          console.log("cry : ", this);
          console.log("cry : ", this.name);
        };
        cry3 = () => {
          console.log("cry : ", this);
          console.log("cry : ", this.name);
        };
      }
      let a = new A("zhangsan");
      console.log(a);

      function B(name) {
        this.name = name;
        this.hobbies = ["swimming"];
        this.shout = function () {
          console.log(this.name + " shouting");
        };
      }
      B.xxx=function(){

      }
      B.prototype.cry = function () {
        console.log("cry : ", this);
        console.log("cry : ", this.name);
      };
      B.prototype.age = 12;

      let b = new B("lisi");

      console.log(b);

      // 对象继承对象 改变原型链
      let c = {
        sex: true,
      };
      c.__proto__ = b;
      console.log("c----------");
      console.log(c);

      console.log("================继承");

      /**    es语法 实现类的继承*/
      class AA extends A {
        constructor(name, money) {
          super(name);
          this.money = money;
        }
        showMoney() {
          console.log(this.name + " show money " + this.money);
        }
      }
      let aa = new AA("吕布", 1000);
      console.log(aa);

      /**  js原生语法 实现类的继承*/
      function BB(name, money) {
        // let a = new A(name);
        // BB 类继承B类的第二步 运行B类的构造函数，效果等于 super(name);
        B.call(this, name);
        //欠账 super extends
        this.money = money;
      }
      // BB类继承B类的第一步 更改原型链 效果等于  AA extends A
      BB.prototype.__proto__ = B.prototype;
      BB.prototype.showMoney = function () {
        console.log(this.name + " show money " + this.money);
      };
      let bb = new BB("曹操", 2000);

      console.log(bb);

      //  new 的等价语法 对象继承于类 也就是 类的实例化 也就是 抽象变具象
      let bbb = {};
      bbb.__proto__ = BB.prototype;
      BB.call(bbb, "王允", 4000);

      console.log("--------new-----关键字等效三行代码");
      console.log(bbb);
      bbb.owner="owner"
      BB.prototype.first="first"
      B.prototype.second="second"
      Object.prototype.third="third"

      console.log(bbb);
    </script>
  </body>
</html>
